using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using WWB.SitePointPrivateMessages.Core.Infrastructure.Logging;
using WWB.SitePointPrivateMessages.Core.Model.Messages;

namespace WWB.SitePointPrivateMessages.Core.Model.DataImport
{
    public class ExportedFolder
    {
        public ExportedFolder()
        {
            Name = "";
            Messages = new ExportedMessage[0];
        }
        [XmlAttribute("name")]
        public string Name { get; set; }

        [XmlElement("privatemessage")]
        public ExportedMessage[] Messages { get; set; }

        public Folder ConvertToFolder(IList<ForumUser> users, ILogger outputLog)
        {
            if (users == null) throw new ArgumentNullException("users");
            if (outputLog == null) throw new ArgumentNullException("outputLog");
            outputLog.LogMessage("Converting folder {0}.", Name);
            var f = new Folder {Name = Name};
            outputLog.LogMessage("There are {0} messages to convert.", Messages.Length);
            foreach (var xpmsg in Messages)
            {
                var m = xpmsg.ConvertToMessage(users, outputLog);
                m.Folder = f;
                f.Messages.Add(m);
            }
            return f;
        }
    }
}